import 'package:flutter/material.dart';

class GoodsListPage extends StatefulWidget {
  @override
  _GoodsListPageState createState() => _GoodsListPageState();
}

class _GoodsListPageState extends State<GoodsListPage> {
  List<Goods> _goods = [];

  void initState() {
    super.initState();
    _goods = [
      Goods(
          name: 'Item 1',
          price: 19.99,
          description: 'This is item 1',
          image: ''),
      Goods(
          name: 'Item 2',
          price: 9.99,
          description: 'This is item 2',
          image: ''),
      Goods(
          name: 'Item 3',
          price: 29.99,
          description: 'This is item 3',
          image: ''),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Goods List'),
      ),
      body: ListView.builder(
        itemCount: _goods.length,
        itemBuilder: (context, index) {
          return Card(
            elevation: 5.0,
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Row(
                children: [
                  Container(
                    width: 150,
                    height: 150,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        //borderRadius: BorderRadius.circular(75),
                        image: const DecorationImage(
                            image: NetworkImage(
                              "https://www.itying.com/themes/itying/images/ionic4.png",
                            ),
                            //fit: BoxFit.cover
                            fit: BoxFit.cover //自动裁剪适配宽高
                            )),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(left: 16.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          _goods[index].name,
                          style: TextStyle(fontWeight: FontWeight.bold),
                        ),
                        Text(
                          '${_goods[index].price}',
                          style: TextStyle(color: Colors.red),
                        ),
                        Text(
                          _goods[index].description,
                          style: TextStyle(fontSize: 16),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}

class Goods {
  String name;
  double price;
  String image;
  String description;

  Goods(
      {required this.name,
      required this.price,
      required this.image,
      required this.description});
}
